{% extends 'generic/object_retrieve.html' %}
{% load buttons %}
{% load custom_links %}
{% load helpers %}
{% load perms %}
{% load plugins %}
{% load tz %}

{% block content %}
    {% if not job_class_found %}
        <div class="alert alert-danger">
            <span class="mdi mdi-alert"></span>
            This job source for this scheduled job is no longer installed.
            This scheduled job will fail to run unless reinstalled at the original location.
        </div>
    {% endif %}
    {{ block.super }}
{% endblock content %}

{% block extra_nav_tabs %}
    {% if perms.extras.view_approvalworkflow and object.associated_approval_workflows.exists %}
        {% if active_tab != 'approval_workflow' and object.get_approval_workflow_url or active_tab == 'approval_workflow' %}
            <li class="nav-item" role="presentation">
                <a href="{{ object.get_approval_workflow_url }}" class="nav-link{% if active_tab == 'approval_workflow' %} active{% endif %}">Approval Workflow</a>
            </li>
        {% endif %}
    {% endif %}
{% endblock extra_nav_tabs %}

{% block content_left_page %}
    <div class="card">
        <div class="card-header">
            <strong>Scheduled Job</strong>
        </div>
        <table class="table table-hover card-body attr-table">
            <tr>
                <td>Name</td>
                <td>
                    {{ object.name }}
                </td>
            </tr>
            <tr>
                <td>Description</td>
                <td>
                    {{ object.description }}
                </td>
            </tr>
            <tr>
                <td>Task</td>
                <td>
                    <code>{{ object.task }}</code>
                </td>
            </tr>
            <tr>
                <td>Job</td>
                <td>{{ object.job_model|hyperlinked_object }}</td>
            </tr>
            <tr>
                <td>Requester</td>
                <td>
                    {{ object.user|placeholder }}
                </td>
            </tr>
            <tr>
                <td>Approval Required?</td>
                <td>{{ object.approval_required | render_boolean }}</td>
            </tr>
            <tr>
                <td>Decision Date</td>
                <td>
                    {{ object.decision_date | placeholder }}
                </td>
            </tr>
        </table>
    </div>
    <div class="card">
        <div class="card-header">
            <strong>Scheduling</strong>
        </div>
        <table class="table table-hover card-body attr-table">
            <tr>
                <td>Enabled?</td>
                <td>{{ object.enabled | render_boolean }}</td>
            </tr>
            <tr>
                <td>Job Queue</td>
                <td>{{ object.job_queue | hyperlinked_object }}</td>
            </tr>
            <tr>
                <td>Interval</td>
                <td>
                    {{ object.interval }}
                    {% if object.interval == "custom" %}({{ object.crontab }}){% endif %}
                </td>
            </tr>
            <tr>
                <td>One Off?</td>
                <td>{{ object.one_off | render_boolean }}</td>
            </tr>
            <tr>
                <td>Start Time</td>
                <td>
                    {{ object.start_time|timezone:object.time_zone|date:settings.SHORT_DATETIME_FORMAT }}
                    {% if default_time_zone != object.time_zone %}
                        {{ object.time_zone }}
                        <br>{{ object.start_time|timezone:default_time_zone|date:settings.SHORT_DATETIME_FORMAT }} {{ default_time_zone }}
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Last Run At</td>
                <td>
                    {% if object.last_run_at %}
                        {{ object.last_run_at|timezone:object.time_zone|date:settings.SHORT_DATETIME_FORMAT }}
                        {% if default_time_zone != object.time_zone %}
                            {{ object.time_zone }}
                            <br>{{ object.last_run_at|timezone:default_time_zone|date:settings.SHORT_DATETIME_FORMAT }} {{ default_time_zone }}
                        {% endif %}
                    {% else %}
                        {{ object.last_run_at|placeholder }}
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>Total Run Count</td>
                <td>
                    {{ object.total_run_count }}
                </td>
            </tr>
        </table>
    </div>
{% endblock %}
{% block content_right_page %}
    {% if job_class_found %}
        <div class="card">
            <div class="card-header">
                <strong>User Inputs</strong>
            </div>
            <table class="table table-hover card-body attr-table">
                {% for key, value in object.kwargs.items %}
                    <tr>
                        <td>{{ labels|get_item:key }}</td>
                        <td>{% if value is None %}–{% else %}<code>{{ value }}</code>{% endif %}</td>
                    </tr>
                {% empty %}
                    <tr><td>—</td></tr>
                {% endfor %}
            </table>
        </div>
    {% endif %}
    <div class="card">
        <div class="card-header">
            <strong>Celery Keyword Arguments</strong>
        </div>
        <div class="card-body">
            {% include 'extras/inc/json_data.html' with data=object.celery_kwargs format="json" %}
        </div>
    </div>
{% endblock %}
